//1314
class Solution {
    public int[][] matrixBlockSum(int[][] mat, int k) {
        int row = mat.length;
        int low = mat[0].length;
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < low; j++) {
                if (i == 0 && j == 0) {
                    continue;
                }
                if (i == 0) {
                    mat[i][j] = mat[i][j] + mat[i][j-1];
                }
                else if (j == 0) {
                    mat[i][j] = mat[i][j] + mat[i-1][j];
                }
                else {
                    mat[i][j] = mat[i][j] + mat[i][j-1] + mat[i-1][j] - mat[i-1][j-1];
                }
            }
        }
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < low; j++) {
                System.out.print(mat[i][j]+" ");
            }
            System.out.println();
        }
        int[][] ret = new int[row][low];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < low; j++) {
                if (i - k > 0 && j - k > 0) {
                    ret[i][j] 
                        = mat[Math.min(row-1, i+k)][Math.min(low-1, j+k)] 
                        + mat[i-k-1][j-k-1]
                        - mat[i-k-1][Math.min(low-1, j+k)] 
                        - mat[Math.min(row-1, i+k)][j-k-1];
                }
                else if (i - k <= 0 && j - k <= 0) {
                    ret[i][j] = mat[Math.min(row-1, i+k)][Math.min(low-1, j+k)];
                }
                else if (i - k <= 0) {
                    ret[i][j] = 
                    mat[Math.min(row-1, i+k)][Math.min(low-1, j+k)]
                    -mat[Math.min(row-1, i+k)][j-k-1];
                }
                else if (j - k <= 0) {
                    ret[i][j] = 
                    mat[Math.min(row-1, i+k)][Math.min(low-1, j+k)]
                    -mat[i-k-1][Math.min(low-1, j+k)];
                }

            }
        }
        return ret;
    }
}
//字符是否为一
class Solution {
    public boolean isUnique(String astr) {
        Set<Character> set = new HashSet<>();
        if (astr == null) {
            return true;
        }
        char[] arr = astr.toCharArray();
        int len = arr.length;
        if (len == 1 || len == 0) {
            return true;
        }
        for (int i = 0; i < len; i++) {
            if (set.contains(arr[i])) {
                return false;
            }
            else {
                set.add(arr[i]);
            }
        }
        return true;
    }
}
//268
class Solution {
    public int missingNumber(int[] nums) {
        int sum = 0;
        int tmp = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += i+1;
            tmp += nums[i];
        }
        return sum - tmp;
    }
}